//
//  BuleModel.m
//  lsOA
//
//  Created by 蓝水软件 on 16/7/20.
//  Copyright © 2016年 苏州蓝水有限公司. All rights reserved.
//

#import "BuleModel.h"

@implementation BuleModel

- (void)getData:(NSString *)fromView{
    switch ([fromView intValue]) {
        case 1:{
            [self getDataInformation];  //公文通告
        }
            break;
        case 2:{
            [self getDataMeetkprocess];  //会议管理
        }
            break;
        case 3:{
            [self getDataDocumentReview];   //公文批阅
        }
            break;
        case 4:{
            [self getDataWorkTask]; //工作任务
        }
            break;
        case 5:{
            [self getDataAddressBook]; //通讯录
        }
            break;
        case 6:{
            [self getDataoperating];    //运营分析
        }
            break;
              default:{
            NSLog(@"异常");
        }
            break;
    }
}

/**
 *  公文通告
 */
- (void)getDataInformation{
    
    NSString *ashx = @"/Server/NewsHandlerNew.ashx";
    NSDictionary *dic = @{@"act":@"gett",@"uname":[UserInfo getUserName],@"upwd":[UserInfo getPassWord]};
    [httpPostRequest getDataByPostAshx:ashx and:dic withFinishBlock:^(id model, NSError *error) {
        if (error == nil) {
            NSString *code = [NSString stringWithFormat:@"%@",[model objectForKey:@"code"]];
            if ([code isEqualToString:@"0"]) {
                NSMutableArray *tableLabelArray = [NSMutableArray new];
                NSMutableArray *tableId = [NSMutableArray new];
                NSMutableArray *cntInfoArray = [NSMutableArray new];
                NSArray *imageArray = [[NSArray alloc]init];
                imageArray = @[@"资讯yellow",@"资讯"];
                NSLog(@"%@",model);
                for (NSDictionary *dic in model[@"data"]) {
                    [tableLabelArray addObject:dic[@"tName"]];
                    [tableId addObject:dic[@"ID"]];
                    [cntInfoArray addObject:dic[@"cntInfo"]];
                    
                }
//                NSArray *messNum = @[@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3"];
                self.tableDic = [NSMutableDictionary new];
                self.tableDic = @{@"tableLabelArray":tableLabelArray,@"tableImageArray":imageArray,@"tableId":tableId,@"cntInfo":cntInfoArray};
                self.block(YES);
            }else{
                [XHToast showCenterWithText:[model objectForKey:@"msg"]];
                self.block(NO);
            }
        }else{
            NSLog(@"错误%@",error);
            self.block(NO);
            [XHToast showBottomWithText:@"请求失败"];
        }
    }];


}
/**
 *  会议管理
 */
- (void)getDataMeetkprocess{
    NSArray *tableLabelArray = @[@"所有会议",@"我参与的",@"我创建的"];
    NSArray *imageArray = [[NSArray alloc]init];
    imageArray = @[@"所有资讯",@"资讯"];
    NSArray *messNum = @[@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3"];
    self.tableDic = [NSMutableDictionary new];
    self.tableDic = @{@"tableLabelArray":tableLabelArray,@"tableImageArray":imageArray,@"messNum":messNum};
    self.block(YES);
}
/**
 *  公文批阅
 */
- (void)getDataDocumentReview{
    NSString *ashx = @"/Server/FlowsHandler.ashx";
    NSDictionary *dic = @{@"act":@"gett",@"uname":[UserInfo getUserName],@"upwd":[UserInfo getPassWord]};
    [httpPostRequest getDataByPostAshx:ashx and:dic withFinishBlock:^(id model, NSError *error) {
        if (error == nil) {
            NSString *code = [NSString stringWithFormat:@"%@",[model objectForKey:@"code"]];
            if ([code isEqualToString:@"0"]) {
                NSLog(@"%@",model);
                NSArray *array = model[@"data"];
                //公文未处理
                NSMutableArray *cntNotDeal = [NSMutableArray new];
                //流程分类
                NSMutableArray *dataArray = [NSMutableArray new];
                //公文类型id
                NSMutableArray *idArray = [NSMutableArray new];
                for (int i = 0; i < array.count; i++) {
                    NSDictionary *dic = array[i];
                    [dataArray addObject:dic[@"TypeName"]];
                    [cntNotDeal addObject:dic[@"cntInfo"]];
                    [idArray addObject:dic[@"ID"]];
                  
                }
                NSArray *imageArray = @[@"任务yellow",@"任务Blue"];
                self.tableDic = @{@"tableLabelArray":dataArray,@"tableImageArray":imageArray,@"cntInfo":cntNotDeal,@"tableId":idArray};
                self.block(YES);
            }else{
                [XHToast showCenterWithText:[model objectForKey:@"msg"]];
                self.block(NO);
            }
        }else{
            NSLog(@"错误%@",error);
            self.block(NO);
            [XHToast showBottomWithText:@"请求失败"];
        }
    }];

    
    
    
}
/**
 *  工作任务
 */
- (void)getDataWorkTask{
    NSString *ashx = @"/Server/TaskHandler.ashx";
    NSDictionary *dic = @{@"act":@"gett",@"uname":[UserInfo getUserName],@"upwd":[UserInfo getPassWord]};
    [httpPostRequest getDataByPostAshx:ashx and:dic withFinishBlock:^(id model, NSError *error) {
        if (error == nil) {
            NSString *code = [NSString stringWithFormat:@"%@",[model objectForKey:@"code"]];
            if ([code isEqualToString:@"0"]) {
                NSMutableArray *tableLabelArray = [NSMutableArray new];
                NSMutableArray *tableId = [NSMutableArray new];
                NSMutableArray *cntInfoArray = [NSMutableArray new];
                NSArray *imageArray = [[NSArray alloc]init];
                imageArray = @[@"任务green",@"任务person"];
                NSLog(@"%@",model);
                for (NSDictionary *dic in model[@"data"]) {
                    [tableLabelArray addObject:dic[@"TypeName"]];
                    [tableId addObject:dic[@"ID"]];
                    [cntInfoArray addObject:dic[@"cntInfo"]];
                    
                }
                self.tableDic = [NSMutableDictionary new];
                self.tableDic = @{@"tableLabelArray":tableLabelArray,@"tableImageArray":imageArray,@"tableId":tableId,@"cntInfo":cntInfoArray};
                self.block(YES);
            }else{
                [XHToast showCenterWithText:[model objectForKey:@"msg"]];
                self.block(NO);
            }
        }else{
            NSLog(@"错误%@",error);
            self.block(NO);
            [XHToast showBottomWithText:@"请求失败"];
        }
    }];
}
/**
 *  通讯录
 */
- (void)getDataAddressBook{
    NSArray *addressBook = @[@"员工通讯录",@"部门通讯录"];
    NSArray *imageArray = [[NSArray alloc]init];
    imageArray = @[@"通讯录1",@"通讯录2"];
    self.tableDic = [NSMutableDictionary new];
      NSArray *messNum = @[@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3",@"3"];
    self.tableDic = @{@"tableLabelArray":addressBook,@"tableImageArray":imageArray,@"messNum":messNum};
    self.block(YES);
}
/**
 *  运营分析
 */
- (void)getDataoperating{
    [XHToast showCenterWithText:@"功能暂未开发.敬请期待."];
}

@end
